Skip to content

fix(metagen): keep typedef'd CF types for block parameters - #116

Open
NathanWalker wants to merge 4 commits into
mainfrom
fix/metagen-block-param-typedefs
Open

NathanWalker wants to merge 4 commits into
mainfrom
fix/metagen-block-param-typedefs

Conversation

@NathanWalker

@NathanWalker NathanWalker commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Split out of #103 (part 3).

Summary

The metadata generator read block parameters from the block's canonical type, which has lost its parameters' typedef names (CMSampleBufferRef becomes struct opaqueCMSampleBuffer *) and with them the CF bridging. Block parameters are now read from the declared (sugared) block type, the same way function, method and delegate parameters already are.

 metadata generator: block parameters
-  read from the canonical type  (CMSampleBufferRef -> struct opaqueCMSampleBuffer *, raw pointer)
+  read from the declared type   (CMSampleBufferRef stays a CF object)

It falls back to the canonical type if the sugared type isn't a block pointer or its arity differs. Neither fallback fires on the current iOS or macOS SDK. C function-pointer callbacks (e.g. CFRunLoopObserverCallBack) are unchanged and still read the canonical type.

Also raises the iOS deployment target from 13.0 to 15.0, in two separate commits. Xcode 27 can't build below 15.0, so without this the iOS run above can't build at all. The change covers the device and simulator targets in NativeScript/CMakeLists.txt, the React Native podspec (and its copy in scripts/test_react_native_ffi_compat.sh), the iOS app template, the libffi build flags and the test runner's TKLiveSync stub. The checked-in libffi archives were built for 13.0 and still link into a 15.0 target.

⚠️ Breaking change (iOS and macOS, once metadata is regenerated)

The generator is shared, so NativeScript iOS apps change too on the next regen:

  • Block parameters typed with CoreFoundation typedefs (CMSampleBufferRef, CGImageRef, CVImageBufferRef, CFErrorRef, SecTrustRef, CFArrayRef, …) arrive in JS as bridged objects instead of interop.Pointer/Reference. A CFStringRef now arrives as a JS string.
  • Typings: about 50 declarations per platform go from interop.PointerConvertible to interop.Object (AVFoundation, CoreMedia, VideoToolbox, Security, CoreText, ImageIO, ReplayKit…). Generic collection blocks (NSArray.enumerateObjectsUsingBlock, NSDictionary.enumerateKeysAndObjectsUsingBlock, diffable data sources…) are now typed with the class's type parameter, a TypeScript-only change that defaults to interop.Object.
  • Migration: pass these values straight to the native APIs that take them; drop pointer-only handling such as .add(), .toNumber(), new interop.Reference(type, ptr), or manual CFRetain/CFRelease of the callback argument.
Regenerated typings iOS (SDK 27.1) macOS
Changed declarations 84 in 17 files 82 in 18 files
CF block params, PointerConvertible → Object 47 decls (53 params) 45 decls (56 params)
Generic block params, Object → type parameter 37 decls (43 params) 33 decls (39 params)
Other none 3: two const T[] params typed interop.Pointer (binary unchanged), and SecTransformSetTransformAction's block now returns interop.Object

Examples: AVCaptureStillImageOutput.captureStillImageAsynchronouslyFromConnectionCompletionHandler (CMSampleBufferRef), AVAssetImageGenerator.generateCGImagesAsynchronouslyForTimesCompletionHandler (CGImageRef), RPScreenRecorder.startCaptureWithHandlerCompletionHandler (CMSampleBufferRef), SecTrustEvaluateAsyncWithError (SecTrustRef, CFErrorRef).

Base and new typings type-check with the same tsc errors (5.6.3), so nothing new.

Relation to #115: the VideoToolbox output-handler case from #103 only queues once metadata is regenerated with this change. With current metadata its CMSampleBufferRef parameter is a raw pointer, so the callback keeps waiting for JS.

Evidence

Both generators went through the same clean pipeline: metadata, GeneratedSignatureDispatch.inc and the TestRunner app metadata were all regenerated, with no checked-in metadata involved.

npm run test:macos npm run test:ios (simulator)
Base generator 716 tests, 0 failures 716 specs, 8 failures
This PR 716 tests, 0 failures 716 specs, 8 failures (the same 8)

The 8 iOS failures are all double/Float64 cases (FunctionWithDouble1, StaticMethodWithDouble1, InstanceMethodWithDouble1, DerivedMethodWithDouble1, functionWithDoublePtr, functionWithFloat64ArrayBuffer, functionWithFloat64ArrayBufferView, NSInvocation_methodWithDouble1), present on the base generator too. The iOS simulator build needs the deployment-target bump below to build under Xcode 27.1.

New regression test in Marshalling/ObjCTypesTests.js ("Block parameters with CF typedefs are marshalled as objects", via CGImageMetadataEnumerateTagsUsingBlock): passes with this generator on both the napi bridge (MACOS_TEST_FFI_BACKEND=napi, 717 tests, 0 failures) and the default V8 bridge (717 tests, 0 failures). It fails with the base generator, where path arrives as an interop.Reference. iOS was not re-run after adding the test.

Merge Danger

Door: one-way for apps (typings and runtime values change on regen)

Blast Radius: every iOS/macOS app that regenerates metadata and uses CF-typed block parameters.

@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 066d00ef-3cb6-42ca-b3ed-7124103cdc3b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ammarahm-ed
ammarahm-ed force-pushed the android-react-native branch 2 times, most recently from 4f87f05 to 9633aba Compare November 8, 2026 12:59
Block parameter types were read from the canonical function type, which
drops typedef sugar: CMSampleBufferRef became struct opaqueCMSampleBuffer *
and lost its CF bridging, so CF block parameters were emitted as raw
pointers. Read them from the declared block type instead, falling back to
the canonical type if the arity differs.
Xcode 27 no longer builds for iOS deployment targets below 15.0, so the
device and simulator builds of NativeScript.xcframework fail at 13.0.
Match the 15.0 deployment target in NativeScript/CMakeLists.txt: the
React Native podspec, the iOS app template, the libffi build and the
test runner's TKLiveSync stub.
@NathanWalker
NathanWalker force-pushed the fix/metagen-block-param-typedefs branch from 2ba50c2 to 000be56 Compare November 20, 2026 21:24
@NathanWalker
NathanWalker changed the base branch from android-react-native to main November 20, 2026 21:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant